package java8;

import java.util.*;
import java.util.Map.Entry;

public class Q5_3 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Map<String, Integer> dict = new HashMap<String, Integer>();
		while(in.hasNext()) {
			String key = in.next();
			Integer value = dict.get(key);
			if(key.equals("!!!!!")) {
				break;
			}
			else {
				if (value == null) {
					dict.put(key, 1);
				} else {
					dict.put(key, ++value);
				}
			}
		}
		List<Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>();
		for (Entry<String, Integer> entry : dict.entrySet()) {
			list.add(entry);
		}
		Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
			public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
				if (o1.getValue() != o2.getValue()) {
					return o2.getValue() - o1.getValue();
				} else {
					return o1.getKey().compareTo(o2.getKey());
				}
			}
		});
		System.out.println(dict.size());
		for (int i = 0; i < 10; i++) {
			System.out.println(list.get(i).toString());
		}
		in.close();	
	}

}